package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements  IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入书籍名称");
        String name=scanner.nextLine();
        int cur=bookList.getUsedSize();
        for(int i=0;i<cur;i++)
        {
            if(bookList.getBook(i).getName().equals(name))
            {
                Book book=bookList.getBook(i);
                if(!book.isBorrowed())
                {bookList.getBook(i).setBorrowed(true);
                    System.out.println("借阅成功");
                    System.out.println(bookList.getBook(i));
                return ;}
                else {
                    System.out.println("已被借");
                    return;

                }
            }
        }
        System.out.println("没有找到该书");
    }
}